package aries;

/******************************************************************************
 * You may modify, publish, and use Aries for your own purpose. BUT
 * DON'T REMOVE THIS TEXT.
 * Visit my facebook: http://www.facebook.com/freeskies or
 * Follow my twitter: @freeskys
 *
 *
 * Author: Harditya Rahmat Ramadhan
 * Licence: GPLv2
 *****************************************************************************/

import java.io.*;
import java.util.Properties;

public class Ini {

    private String file;

    /**
     * Constructor to read and write .ini file.
     *
     * @param file
     */
    public Ini(String file) {
        this.file = file;
    }

    /**
     * Get value from .ini file.
     *
     * @param title
     * @return value
     * @throws IOException
     */
    public String getValue(String title)
    throws IOException {
        Properties properties = new Properties();
        properties.load(new FileInputStream(file));
        return properties.getProperty(title);
    }

    /**
     * Create a new .ini file.
     *
     * @param title
     * @param value
     * @throws IOException
     */
    public void create(String[] title, String[] value)
    throws IOException {
        create(title, value, "");
    }
    
    public void create(Object[] title, Object[] value)
    throws IOException {
        create(title, value, "");
    }

    /**
     * Create a new .ini file.
     *
     * @param title
     * @param value
     * @param comments
     * @throws IOException
     */
    public void create(String title[], String value[], 
    String comments) throws IOException {
        Properties properties = new Properties();
        for (byte i=0; i<title.length; i++)
            properties.put(title[i], value[i]);
        properties.store(new FileOutputStream(file), comments);
    }
    
    /**
     * Create a new .ini file.
     * 
     * @param title
     * @param value
     * @param comments
     * @throws IOException 
     */
    public void create(Object[] title, Object[] value, 
    String comments) throws IOException {
        Properties properties = new Properties();
        for (byte i=0; i<title.length; i++)
            properties.put(title[i], value[i]);
        properties.store(new FileOutputStream(file), comments);
    }
    
}